package com.example.highclasscomponent;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.highclasscomponent.adapter.BillListAdapter;
import com.example.highclasscomponent.database.BillDBHelper;
import com.example.highclasscomponent.pojo.BillInfo;

import java.util.List;

public class BillPagerFragment extends Fragment {

    public static BillPagerFragment newInstance(String yearMonth) {
        BillPagerFragment fragment = new BillPagerFragment();
        Bundle arguments=new Bundle();
        arguments.putString("yearMonth",yearMonth);
        fragment.setArguments(arguments);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        String yearMonth = getArguments().getString("yearMonth");
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_bill_pager, container, false);
        ListView lv_bill=view.findViewById(R.id.lv_bill);
        BillDBHelper mDBHelper=BillDBHelper.getInstance(getContext());
        List<BillInfo> billInfos = mDBHelper.queryByMonth(yearMonth);
        for (BillInfo billInfo : billInfos) {
            Log.d("tang", "onCreateView: "+billInfo.toString());
        }
        BillListAdapter adapter=new BillListAdapter(getContext(),billInfos);
        lv_bill.setAdapter(adapter);
        return view;
    }
}